+2006-03-03 Matthias Clasen <mclasen@redhat.com>
+
+ * io-pnm.c: Support pnm files with maxval > 255.
+ (#327560, Matthijs Douze)
+
2006-03-03 Matthias Clasen <mclasen@redhat.com>
* io-pcx.c (pcx_load_palette_8): Fix incremental loading
return PNM_FATAL_ERR;
}
- if (context->maxval > 255) {
- g_set_error (context->error,
- GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
- _("Cannot handle PNM files with maximum color values greater than 255"));
- return PNM_FATAL_ERR;
- }
}
break;
default:
_("Raw PNM image type is invalid"));
return PNM_FATAL_ERR;
}
+ if(context->maxval>255)
+ numpix/=2;
numpix = MIN (numpix, context->width - context->output_col);
_("Raw PNM image type is invalid"));
return PNM_FATAL_ERR;
}
+ if(context->maxval>255)
+ numbytes*=2;
switch (context->type) {
case PNM_FORMAT_PBM_RAW:
if (context->maxval == 255) {
/* special-case optimization */
memcpy (dest, inbuf->byte, numbytes);
+ } else if(context->maxval == 65535) {
+ /* optimized version of the next case */
+ for(i=0; i < numbytes ; i+=2) {
+ *dest++=inbuf->byte[i];
+ }
+ } else if(context->maxval > 255) {
+ /* scale down to 256 colors */
+ for(i=0; i < numbytes ; i+=2) {
+ guint v=inbuf->byte[i]*256+inbuf->byte[i+1];
+ *dest++=v*255/context->maxval;
+ }
} else {
for (i = 0; i < numbytes; i++) {
guchar *byte = inbuf->byte + i;
break;
case PNM_FORMAT_PGM:
case PNM_FORMAT_PPM:
- /* scale the color to an 8-bit color depth */
+ /* scale the color up or down to an 8-bit color depth */
if (value > context->maxval)
*dptr++ = 255;
else